import 'package:flutter/material.dart';
import './components/MainCart.dart';
import './components/MainCategory.dart';
import './components/MainHome.dart';
import './components/MainMine.dart';



class MainPage extends StatefulWidget {
  const MainPage({ super.key });

  @override
  _MainPage createState() => _MainPage();
}

class _MainPage extends State<MainPage> {
  int currentIndex = 0; // 当前激活的索引

  List<BottomNavigationBarItem> getBottomNavigorBar () {
    List<BottomNavigationBarItem> list = [];
    list.add(BottomNavigationBarItem(
      icon: Image.asset(
        'tabbar/home.png',
          width: 32,
         height:32
      ),
      label: "首页",
      activeIcon: Image.asset(
        'tabbar/home-active.png',
          width: 32,
         height:32
      )
  
    ));

    list.add(BottomNavigationBarItem(
      icon: Image.asset(
        'tabbar/cate.png',
          width: 32,
         height:32
      ),
      label: "分类",
      activeIcon: Image.asset(
        'tabbar/cate-active.png',
          width: 32,
         height:32
      )
  
    ));
    list.add(BottomNavigationBarItem(
      icon: Image.asset(
        'tabbar/cart.png',
          width: 32,
         height:32
      ),
      label: "购物车",
      activeIcon: Image.asset(
        'tabbar/cart-active.png',
          width: 32,
         height:32
      )
  
    ));
     list.add(BottomNavigationBarItem(
      icon: Image.asset(
        'tabbar/user.png',
          width: 32,
         height:32
      ),
      label: "我的",
      activeIcon: Image.asset(
        'tabbar/user-active.png',
          width: 32,
         height:32
      )
  
    ));
    return list;
  

    
  }

  @override
  Widget build(BuildContext context) {
   return  Scaffold(
     body: SafeArea(child: 
     IndexedStack(
       index: currentIndex,
       children: const [
          MainHome(),
          MainCategory(),
          MainCart(),
          MainMine()
       ],
     )
     ),
     bottomNavigationBar: BottomNavigationBar(
      type: BottomNavigationBarType.fixed,
      items: getBottomNavigorBar(),
      selectedItemColor: Colors.red,
      unselectedItemColor: Colors.black,
      currentIndex: currentIndex,
      onTap: (index) {
        setState(() {
            currentIndex = index;
        });
      
      },
      ),
   );
  }
}